//
//  WebViewController.m
//  Grammar
//
//  Created by Rick on 7/14/13.
//
//

#import "WebViewController.h"
#import "AppDelegate.h"

@interface WebViewController ()<UIWebViewDelegate>
@property (retain, nonatomic) IBOutlet UIWebView *contentWebView;
@property (retain, nonatomic) IBOutlet UILabel *titleLabel;

@end

@implementation WebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self showContentWithWebType:_type];
    if (!isReachability) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"无网络连接" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil];
        [alertView show];
        [alertView release];
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[AppDelegate shareAppdelegate].homeTabbarController hideTabBarAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)tapBackButton:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dealloc {
    [_contentWebView release];
    [_titleLabel release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setContentWebView:nil];
    [self setTitleLabel:nil];
    [super viewDidUnload];
}

- (void)showContentWithWebType:(WebviewContentType)type
{
    switch (type) {
        case WebviewContentTypeFeedback:
        {
            _titleLabel.text = @"意见反馈";
            [_contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://121.199.38.186/satgrammar/intf/soft/feedback.intf"]]];
        }
            break;
        case WebviewContentTypeGoodComment:
        {
            [_contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://121.199.38.186/satgrammar/intf/soft/updateVersion.intf"]]];
        }
            break;
        case WebviewContentTypeHelpUse:
        {
            _titleLabel.text = @"使用说明";
            [_contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://121.199.38.186/satgrammar/intf/soft/softHelp.intf"]]];
        }
            break;
        case WebviewContentTypeRelief:
        {
            _titleLabel.text = @"免责说明";
            [_contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://121.199.38.186/satgrammar/intf/soft/reliefExplain.intf"]]];
        }
            break;
        default:
            break;
    }
}
@end
